var get_url_params = function(url, name) {
    var a = document.createElement("a");
    a.href = url;
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(a.search)||[,null])[1]
    );
}

var base_render = {
    handler:   function(items) {
        console.log(items);
    },

    error_handler:   function(items) {
    },

    components: {
        page: jQuery("div[data-role='page']")
    },

    options: {
    },

    post_render: function(){
        jQuery.mobile.loading("hide");
    },

    render: function(url, params) {
        var _render = this;
        params = params || {};
        jQuery.getJSON(url, params, function(items){
            _render.handler(items);
            _render.post_render();
        }).error(_render.error_handler);
    }
};

// Update the contents of the toolbars
$( document ).on( "pageshow", "[data-role='page']", function() {
    // Each of the four pages in this demo has a data-title attribute
    // which value is equal to the text of the nav button
    // For example, on first page: <div data-role="page" data-title="Info">
    var current = $( this ).jqmData( "title" );
    // Change the heading
    // $( "[data-role='header'] h1" ).text( current );
    // Remove active class from nav buttons
    $( "[data-role='navbar'] a.ui-btn-active" ).removeClass( "ui-btn-active" );
    // Add active class to current nav button
    $( "[data-role='navbar'] a" ).each(function() {
        if ( $( this ).text() === current ) {
            $( this ).addClass( "ui-btn-active" );
        }
    });
});
